package nl.unimaas.micc.umsnooker.domain;

import java.util.HashSet;
import java.util.Set;

import nl.unimaas.micc.umsnooker.simulation.physics.BallMotion;
import nl.unimaas.micc.umsnooker.simulation.physics.Physics;

import com.jme.math.Vector3f;

public abstract class Ball extends SphericalGameObject
{
	public enum BallState
	{
		RESTING(Physics.getRestingMotion()),
		SLIDING(Physics.getSlidingMotion()),
		ROLLING(Physics.getRollingMotion());

		BallState(BallMotion motion)
		{
			this.motion = motion;
		}

		public BallMotion getMotion()
		{
			return motion;
		}

		private BallMotion motion;
	}

	public Ball()
	{
		tiles = new HashSet<Tile>();
	}

	public Ball(Vector3f position)
	{
		setPosition(position);
	}

	public Vector3f getAngularVelocity()
	{
		return angularVelocity;
	}

	public void setAngularVelocity(Vector3f av)
	{
		this.angularVelocity = av;
	}

	public Vector3f getVelocity()
	{
		return velocity;
	}

	public void setVelocity(Vector3f velocity)
	{
		this.velocity = velocity;
	}

	public float getTime()
	{
		return time;
	}

	public void setTime(float time)
	{
		this.time = time;
	}

	@Override
	public String toString()
	{
		return "t:" + time + ", p:" + getPosition().x+"|"+getPosition().y+"|"+getPosition().z + ", v:" + velocity.x+"|"+velocity.y+"|"+velocity.z + ", |v|:"
				+ velocity.length() + ", av:" + angularVelocity.x+"|"+angularVelocity.y+"|"+angularVelocity.z + "|u|:"
				+ Physics.getRelativeVelocity(this).length() + "Mass: "
				+ this.getMass() + ", state:" + this.getState();
	}

	public BallState getState()
	{
		return state;
	}

	public void setState(BallState state)
	{
		this.state = state;
	}

	public void setMass(float mass)
	{
		this.mass = mass;
	}

	public float getMass()
	{
		return mass;
	}
	
	public float getFriction()
	{
		return friction;
	}
	
	public void setFriction(float friction)
	{
		this.friction = friction;
	}
	
	public Set<Tile> getTiles()
	{
		return tiles;
	}
	
	public void setTiles(Set<Tile> tiles)
	{
		this.tiles = tiles;
	}

	private Vector3f velocity = Vector3f.ZERO.clone();
	private Vector3f angularVelocity = Vector3f.ZERO.clone();
	private float time;
	private float mass;
	private BallState state = BallState.RESTING;
	private float friction;
	private Set<Tile> tiles;


}
